// ElementDefObjectFactoryVersionOne.cpp: implementation of the ElementDefObjectFactoryVersionOne class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ElementDefObjectFactoryVersionOne.h"
#include "ElementDefinition.h"
#include "ElementDefVersionOne.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace Specification
{
	ElementDefObjectFactoryVersionOne::ElementDefObjectFactoryVersionOne()
	{

	}

	ElementDefObjectFactoryVersionOne::~ElementDefObjectFactoryVersionOne()
	{

	}
	
	ElementDefPtr ElementDefObjectFactoryVersionOne::NewObject(typeElementDefItem& item)
	{
		if (item->IsEmpty())
		{
			return NULL;
		}

		ElementDefPtr elementDef(new ElementDefVersionOne);
		elementDef->SetType(item->GetString(_T("TYPE")));
		elementDef->SetSource(item->GetString(_T("DataFromMdb")));
		elementDef->SetIndex(item->GetShort(_T("INDEX")));
		elementDef->SetUnit(item->GetString(_T("UnitType")));

		StdString strMinField;
		StdString strMaxField;
		StdString strEndTypeField;
		StdString strEndTypeValue;
		LONG nMin = 0;
		LONG nMax = 0;
		EndFacePtr tmpEndFace;
		for (int i=0; i<EndFaceNum; i++)
		{	
			tmpEndFace = new EndFace;
			strMinField = _T("DN_MIN");
			strMaxField = _T("DN_MAX");
			strEndTypeField = _T("ENDTYPE");
			if (i > 0)
			{
				strMinField.Insert(2, i+48);
				strMaxField.Insert(2, i+48);
				strEndTypeField.Insert(7, i+48);
			}
			nMin = item->GetLong(strMinField);
			nMax = item->GetLong(strMaxField);
			strEndTypeValue = item->GetString(strEndTypeField);
			
			tmpEndFace->SetDNMin(nMin);
			tmpEndFace->SetDNMax(nMax);
			tmpEndFace->SetEndType(strEndTypeValue);

			elementDef->SetEndFace(tmpEndFace);

		}
		return elementDef;
	}
	
}
